<!DOCTYPE html>
<html lang="zh_CN">
<head>
<#--引入外部文件-->
    <#include "../common/header.ftl">
</head>
<body>

<div class="container" style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">景点管理</h1>
                </div>
            </div>
        <#--高级查询--->
            <form class="form-inline" id="searchForm" action="/ticketes/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入地区或景点名称">
                </div>
                <button id="btn_query" class="btn btn-default">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a href="javascript:" class="btn btn-success inputBtn">
                    <span class="glyphicon glyphicon-plus"></span> 添加景点
                </a>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>编号</th>
                    <th>地区</th>
                    <th>景点名称</th>
                    <th>图片</th>
                    <th>价格/￥</th>
                    <th>地点</th>
                    <th>创建时间</th>
                    <th>编辑</th>
                </tr>
            <#--使用Freemark的指令完成循环迭代-->
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index + 1}</td>
                        <td>${(entity.region)!}</td>
                        <td>${(entity.name)!}</td>
                        <td><img src="${(entity.pictureImg)!}" width="35px"/></td>
                        <td>${(entity.price)!}</td>
                        <td>${(entity.street)!}</td>
                        <td>${(entity.creationTime?string("yyyy-MM-dd HH:mm"))!}</td>

                        <td>
                            <a href="javascript:" class="btn btn-info btn-xs inputBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-pencil"></span> 编辑
                            </a>
                            <a href="javascript:" class="btn btn-danger  btn-xs deleteBtn" data-tid="${entity.id}">
                                <span class="glyphicon glyphicon-remove"></span> 删除
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>

            <#include "../common/page.ftl">
        </div>
    </div>
</div>

<#--模态框必须是body的子元素-->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog ">
        <div class="modal-content">
        <#--模态框标题-->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">新增/编辑</h4>
            </div>
        <#--模态框正文-->
            <div class="modal-body">
            <#--填充编辑界面-->
                <form class="form-horizontal" action="/ticketes/save.do" method="post" id="ticketForm"
                      enctype="multipart/form-data">
                <#--隐藏产品id-->
                    <input type="hidden" name="id"/>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">地区：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="region" placeholder="请输入地区名称"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">景点名称：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="name" placeholder="请输入景点名称"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">图片：</label>
                        <div class="col-lg-6">
                            <img id="coverImg" width="100%"> <!--用来显示-->
                            <input type="hidden" class="form-control" name="pictureImg"/><!--用来提交表单(回显)-->
                            <input type="file" class="form-control" name="file"/><!--用来提交表单(上传)-->
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">价格：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="price" placeholder="请输入景点价格"/>
                        </div>
                    </div>


                    <div class="form-group">
                        <label class="col-lg-4 control-label">地点</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="street" placeholder="输入地点"/>
                        </div>
                    </div>

                </form>

            </div>
        <#--模态框底部按钮-->
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary ticketBtn">保存</button>
            </div>
        </div>
    </div>
</div>

<!--引入ckeditor-->
<script src="/js/plugins/ckeditor/ckeditor.js"></script>
<script>
    $(function () {
        // 初始化ckeditor
        /*---------------------------------------------------------------------------*/
        // 点击保存，模态框提交表单
        $(".ticketBtn").click(function () {
            $("#ticketForm").submit();
        });
        /*--------------------------------------------------------------------------*/

        //删除景点
        $(".deleteBtn").click(function () {
            var id = $(this).data("tid");
            $.get("/ticketes/delete.do", {id: id}, function (data) {

            })
        })

        // 点击编辑或添加，弹出模态框
        $(".inputBtn").click(function () {
            // 清空模态框
            $("#inputModal input").val("");
            $("#coverImg").attr('src', '');
            // 获取当前按钮中的自定义JSON对象（仅编辑按钮绑定json对象）
            var obj = $(this).data("json");
            console.log(obj);

            // 编辑按钮做数据回显
            if (obj) {
                $("#inputModal input[name='id']").val(obj.id);
                $("#inputModal input[name='region']").val(obj.region);
                $("#inputModal input[name='name']").val(obj.name);
                // 修改时选择下拉框回显保险类型
                $("#inputModal input[name='price']").val(obj.price);
                $("#inputModal select[name='state']").val(obj.state);
                $("#inputModal input[name='street']").val(obj.street);
                $("#inputModal input[name='pictureImg']").val(obj.pictureImg);
                $("#coverImg").attr('src', obj.pictureImg);
            }
            $("#inputModal").modal('show');
        });

        /*--------------------------------------------------------------------------*/
    });
</script>

</body>
</html>